
# ----------------类的描述符---------------------------
class Type:
    def __init__(self,key,expection_type):
        self.key=key
        self.expection_type=expection_type
    def __get__(self, instance, owner):
        return instance.__dict__[self.key]
    def __set__(self, instance, value):
        if not isinstance(value,self.expection_type):
            raise TypeError("%s传入的类型不是%s" %(self.key,self.expection_type))
        instance.__dict__[self.key]=value

    def __delete__(self, instance):
        instance.__dict__.pop(self.key)
class People:
    name=Type("name",str)
    age = Type("age", int)
    gendler = Type("gendler", str)
    saraly=Type("saraly",float)
    def __init__(self,name,age,gendler,saraly):
        self.name = name
        self.age = age
        self.gendler = gendler
        self.saraly = saraly
p1=People("alex",16,"女",543.0)
print(p1.__dict__)